#include "video_windows.h"
#include "ui_video_windows.h"

#include <QMediaPlayer>
#include <QVideoWidget>
#include <QtWidgets>
video_windows::video_windows(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::video_windows)
{
    ui->setupUi(this);
    QMediaPlayer *player = new QMediaPlayer;
    QVideoWidget* videoWidget = new QVideoWidget(this);
    setWindowTitle("video");
    //将视频显示组件窗口添加到QVBoxLayout垂直布局
    ui->verticalLayout->addWidget(videoWidget);


//    player->setMedia(QUrl::fromLocalFile("H:/desk/emotionGUI_V1/AllVideo/1.1.mp4"));

    videoWidget->resize(600,300);
    player->setVideoOutput(videoWidget);
    player->setMedia(QUrl::fromLocalFile(
    			"/home/jetson/bigSystem/Neurofeedback_regulation/AllVideo/1.1.mp4"));

    // 2.界面美化
    QPalette qplte;// 调色板
//    qplte.setColor(QPalette::Window, QColor(0,0,0));// 透明
    //给VideoWidget画上黑色的背景，这样会更专业点（默认是灰白色的）
    // qplte.setBrush(QPalette::Background, Qt::black);
    videoWidget->setPalette(qplte);// 设置窗口部件的调色板
    // 设置视频小部件是否自动填充背景。true则视频小部件将自动填充背景，以便在视频播放期间保持视觉效果。
    // videoWidget->setAutoFillBackground(true);


    player->play();

    connect(player, &QMediaPlayer::stateChanged, [=](QMediaPlayer::State state) {
        if (state == QMediaPlayer::StoppedState) {
            qDebug() << "Media playback finished!";
        }
    });

    player->play();
}
void video_windows::keyPressEvent(QKeyEvent *event){
    if (event->key() == Qt::Key_Escape) {
        showNormal();
    }
}

void video_windows::mouseDoubleClickEvent(QMouseEvent *event){
    if (event->button() == Qt::LeftButton) {
        if (isFullScreen()) {
            showNormal();
        } else {
            showFullScreen();
        }
    }
}
video_windows::~video_windows()
{
    delete ui;
}
